import { Component } from '@angular/core';
import {AuthService} from "@core/service/AuthService";
import {FileUploadService} from "@core/service/FileUploadService";
import {ActivatedRoute, NavigationEnd, Router} from "@angular/router";
import {SharePageService} from "@core/service/page/SharePageService";
import {MyDiskPageService} from "@core/service/page/MyDiskPageService";
import {BBYUtils} from "@shared/utils/BBYUtils";
import {ClassifyPageService} from "@core/service/page/ClassifyPageService";
import {PmMessage} from "@shared/models/PmMessage";
import {PmMessageService} from "@core/service/PmMessageService";
import {NzModalService} from "ng-zorro-antd/modal";

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title='破破的共享盘'
  size = '30%';
  constructor(
    public authService:AuthService,
    public fileUploadService : FileUploadService,
    private router:Router,
    private sharePageService:SharePageService,
    private myDiskPageService:MyDiskPageService,
    private classifyPageService:ClassifyPageService,
    private activatedRoute:ActivatedRoute,
    public pmReqService:PmMessageService
  ) {
    authService.flashUserInfo()
    pmReqService.flash()
    this.router.events.subscribe((event) => {
      if (event instanceof NavigationEnd) {
        let params = this.activatedRoute.snapshot.queryParams
        if (event.url.startsWith("/share")){
          sharePageService.dealUrl(event.url.split('?')[0],params)
          // sharePageService.loadPath(decodeURI(event.url).substring(7))
        }else if (event.url.startsWith("/myDisk")){
          myDiskPageService.dealUrl(event.url.split('?')[0],params)
        }else if (event.url.startsWith("/classify")){
          classifyPageService.loadCategory(params.id)
        }
      }
    });
  }
  menu={
    classify:[
      {
        title: '图片',
        link: '/classify',
        icon:'file-image',
        id:'image'
      },
      {
        title: '文档',
        link: '/classify',
        id:'text',
        icon:'file-text'
      },
      {
        title: '视频',
        link: '/classify',
        id:'video',
        icon:'video-camera'
      },
      {
        title: '音频',
        link: '/classify',
        id:'audio',
        icon:'audio'
      },
      {
        title: '压缩包',
        link: '/classify',
        id:'zip',
        icon:'file-zip'
      },
    ],
    share:[
      {
        title: '共享大厅',
        link: '/share',
        icon:'share-alt'
      }
    ],
    myFile:[
      {
        title: '全部文件',
        link: '/myDisk',
        icon:'cloud-server'
      },
      {
        title: '文件分类',
        link: '/classify',
        icon:'appstore'
      }
    ],
    user:[
      {
        title: '用户信息',
        link: '/user/userinfo',
        icon:'info-circle'
      },
      {
        title: '个人设置',
        link: '/user/setting',
        icon:'setting'
      },
      {
        title: '我的收藏',
        link: '/user/favorite',
        icon:'star'
      }
    ]
  }
  isCollapsed: boolean=false;


  menuClick(item:{title:string,link:string}){
    console.log(item)

  }
  sizeChange(size:any) {
    console.log(size);
  }
  collapsedChange(event:any) {
    console.log(event);
  }

  openPageRecovery(item: { link: string; icon: string; title: string }) {
    let url;
    let queryParams;
    if (item.title=='共享大厅'){
      url = this.sharePageService.openUrl
    }else if (item.title=='我的网盘'){
      url = this.myDiskPageService.openUrl
    }
    if (url){
      queryParams=this.router.parseUrl(url).queryParams
      console.log(url.split('?')[0])
      this.router.navigate([url.split('?')[0]],{queryParams})
    }else {
      this.router.navigate([item.link])
    }
  }
}
